﻿using nplJobsCommon.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nplJobsDAL.Select
{
    /// <summary>
    /// Select designations from the database
    /// </summary>
    public class SelectDesignation : DataAccessBase
    {
        public SelectDesignation()
        {
            StoredProcedureName = StoredProcedure.Name.spDesignation.ToString();
        }

        #region GetDesignation
        public List<Designation> GetDesignation()
        {
            DataBaseHelper dbHelper;
            DataSet dsDesignation;

            try
            {
                dbHelper = new DataBaseHelper(StoredProcedureName);
                dsDesignation = dbHelper.Run(base.ConnectionString);
                return GetList(dsDesignation);
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region GetList
        private List<Designation> GetList(DataSet dsDesignation)
        {
            List<Designation> designations;
            try
            {
                designations = (from d in dsDesignation.Tables[0].AsEnumerable()
                                select new Designation
                              {
                                  ID = d.Field<int>("ID"),
                                  DesignationName = d.Field<string>("Designation")
                              }).ToList();

                return designations;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }
        }
        #endregion
    }
}
